package com.group02.community.service.impl;

import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.group02.community.entity.vo.SuggestVO;
import com.group02.community.mapper.SuggestMapper;
import com.group02.community.service.ISuggestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@Service
public class SuggestServiceImpl extends ServiceImpl<SuggestMapper, SuggestVO> implements ISuggestService {
    @Autowired
    private SuggestMapper suggestMapper;

    @Override
    public void downloadExcel(HttpServletResponse response) throws IOException {
        List<SuggestVO> suggestVOS= suggestMapper.selectAllSuggest();
        //设置文件下载
        //设置响应头，告诉浏览器要以文件的形式保存
//        response.setHeader();
        response.setHeader("content-disposition","attachment;filename="+System.currentTimeMillis()+".xlsx");
        //生成Excel并写入
        EasyExcel.write(response.getOutputStream(), SuggestVO.class).sheet(System.currentTimeMillis()+"").doWrite(suggestVOS);
    }

    @Override
    public IPage<SuggestVO> getSuggestPage(Long current, Long size,SuggestVO suggestVO) {
        return suggestMapper.selectSuggestPage(new Page<SuggestVO>(current,size),suggestVO);
    }

    @Override
    public List<SuggestVO> selectAllSuggest() {
        return suggestMapper.selectAllSuggest();
    }

    @Override
    public void addSuggest(SuggestVO suggestVO) {
        suggestMapper.addSuggest(suggestVO);
    }

    @Override
    public void addOwner(SuggestVO suggestVO) {
        suggestMapper.addOwner(suggestVO);
    }
}

